import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useUser = defineStore('user', () => {
    const loginfrom = ref(false)
    const user = ref(
        {
            userId: 1841672494,
            nickname: 'admin',
            avatarUrl: "http://p1.music.126.net/60FEwxJNqqRQYqxSeNxXSg==/109951164503464664.jpg",
            createTime: 1568389689793,
            lastLoginIP: "120.235.232.194"
        }
    )
    const updateUser = (newUser) => {
        user.value = newUser
    }
    const removeUser = () => {
        user.value = {
            userId: 1841672494,
            nickname: '游客1',
            avatarUrl: "http://up.quarkzhong.top/imgs/2023/11/04cdd9a93cac6462.png",
            createTime: 0,
            lastLoginIP: "120.235.232.194"
        }
    }
    return { loginfrom, user, updateUser, removeUser }
},
    {
        persist: {
            enabled: true,
            strategies: [
                {
                    storage: window.localStorage,
                    key: 'user'
                }
            ]
        }
    })
